home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 0411.ZIP / STRVALS.C < prev    next >
Text File  |  1985-10-11  |  4KB  |  190 lines

  1. /*
  2.  * Program to read the keyboard and return the hex and decimal equivalent.
  3.  */
  4. int scr_cols,
  5.     scr_rows,
  6.     scr_mode,
  7.     scr_page,
  8.     scr_attr;
  9. #include "stdio.h"
  10. main(argc,argv)
  11.     int argc;
  12.     char *argv[];
  13.     {
  14.     extern int scr_cols,
  15.            scr_rows,
  16.            scr_mode,
  17.            scr_page,
  18.            scr_attr;
  19.     char headmsg[61];
  20.     int  inchar,
  21.      lastrow,
  22.      lastcol,
  23.      mode,
  24.      page,
  25.      cntr,
  26.      attr,
  27.      finished,
  28.      lopart,
  29.      medpart,
  30.      hipart,
  31.      redblu,
  32.      magblu,
  33.      grnblu,
  34.      yelblu,
  35.      blue;
  36.     /*
  37.      * Check if version information was asked for
  38.      */
  39.     if (argc > 1)
  40.     {
  41.     if (argv[1][0] == '#')
  42.         {
  43.         puts("\n");
  44.         puts("PROGRAM: STRVALS\n");
  45.         puts("Author : Peter Townsend\n");
  46.         puts("Date   : 11Oct85\n");
  47.         puts("Version: 1.0\n");
  48.         exit(0);
  49.         }
  50.     }
  51.     /*
  52.      * Initialise
  53.      */
  54.     redblu = 0x1c;
  55.     yelblu = 0x1e;
  56.     magblu = 0x1d;
  57.     grnblu = 0x1a;
  58.     blue = 0x1;
  59.     strcpy(headmsg,"Enter a string to see its hex and decimal values");
  60.     /*
  61.      * Initialise screen handling facilities
  62.      */
  63.     scr_setup();
  64.     /*
  65.      * Store current screen state
  66.      */
  67.     mode = scr_mode;
  68.     attr = scr_attr;
  69.     page = scr_page;
  70.     /*
  71.      * Set new screen state
  72.      */
  73.     scr_setmode(3);
  74.     scr_color(0,blue);
  75.     scr_attr = redblu;
  76.     scr_clr();
  77.     /*
  78.      * Set cursor position to 3rd line
  79.      */
  80.     lastrow = 2;
  81.     lastcol = 0;
  82.     /*
  83.      * Print the function heading at the top of the screen
  84.      */
  85.     cntr = (scr_cols - strlen(headmsg)) / 2;
  86.     scr_rowcol(0,cntr);
  87.     for(cntr=0;cntr<strlen(headmsg);cntr++)
  88.     {
  89.     scr_co_atr(headmsg[cntr],grnblu);
  90.     scr_rowcol(0,scr_scol()+1);
  91.     }
  92.     scr_rowcol(lastrow,lastcol+2);
  93.     inchar = ci();
  94.     while (inchar != 0xd)
  95.     {
  96.     while (inchar != 0xd)
  97.         {
  98.         /*
  99.          * Print the character
  100.          */
  101.         scr_co_atr(inchar,magblu);
  102.         /*
  103.          * Seperate the character into hi and lo parts of a hex value
  104.          */
  105.         hipart = inchar / 0x10;
  106.         lopart = inchar % 0x10;
  107.         if ((hipart >= 0) && (hipart <=9))
  108.         {
  109.         hipart = hipart + '0';
  110.         }
  111.         else
  112.         {
  113.         hipart = hipart + 'A' - 0xa;
  114.         }
  115.         if ((lopart >= 0) && (lopart <=9))
  116.         {
  117.         lopart = lopart + '0';
  118.         }
  119.         else
  120.         {
  121.         lopart = lopart + 'A' - 0xa;
  122.         }
  123.         /*
  124.          * Print the hex value underneath the character
  125.          */
  126.         scr_rowcol(lastrow+1,lastcol+1);
  127.         scr_co_atr(hipart,yelblu);
  128.         scr_rowcol(lastrow+1,lastcol+2);
  129.         scr_co_atr(lopart,yelblu);
  130.         /*
  131.          * Seperate the character into hi, med, and lo parts of a dec value
  132.          */
  133.         hipart = inchar / 0x64;
  134.         medpart = (inchar % 0x64) / 0xa;
  135.         lopart = (inchar % 0x64) % 0xa;
  136.         hipart  = hipart  + '0';
  137.         lopart  = lopart  + '0';
  138.         medpart = medpart + '0';
  139.         /*
  140.          * Print the dec value underneath the hex values
  141.          */
  142.         scr_rowcol(lastrow+2,lastcol);
  143.         scr_co_atr(hipart,redblu);
  144.         scr_rowcol(lastrow+2,lastcol+1);
  145.         scr_co_atr(medpart,redblu);
  146.         scr_rowcol(lastrow+2,lastcol+2);
  147.         scr_co_atr(lopart,redblu);
  148.         /*
  149.          * Check row/column values for input of next character
  150.          */
  151.         lastcol = lastcol + 4;
  152.         if (lastcol >= scr_cols)
  153.         {
  154.         lastcol = 0;
  155.         lastrow = lastrow + 4;
  156.         if ((lastrow+1) >= scr_rows)
  157.             {
  158.             scr_scup();
  159.             scr_scup();
  160.             scr_scup();
  161.             scr_scup();
  162.             lastrow = lastrow - 4;
  163.             }
  164.         }
  165.         scr_rowcol(lastrow,lastcol+2);
  166.         inchar = ci();
  167.         }
  168.     lastcol = 0;
  169.     lastrow = lastrow + 4;
  170.     if (lastrow >= scr_rows)
  171.         {
  172.         scr_scup();
  173.         scr_scup();
  174.         scr_scup();
  175.         scr_scup();
  176.         lastrow = lastrow - 4;
  177.         }
  178.     scr_rowcol(lastrow,lastcol+2);
  179.     inchar = ci();
  180.     }
  181.     /*
  182.      * Restore previous screen environment
  183.      */
  184.     scr_setmode(mode);
  185.     scr_attr = attr;
  186.     scr_page = page;
  187.     scr_clr();
  188.     exit(0);
  189.     }
  190.